from wxauto import WeChat
from wxauto.msgs import FriendMessage
import mysql.connector

# 数据库连接配置
DB_CONFIG = {
    "host": "sh-cdb-5cce1w3k.sql.tencentcdb.com",
    "port": 23403,
    "user": "public",
    "password": "Aa19891216",
    "database": "bank_msg_push",
    "charset": "utf8mb4",
    "use_unicode": True,
    "autocommit": True,
}

# 数据库查询函数
def get_last_record():
    try:
        conn = mysql.connector.connect(**DB_CONFIG)
        cursor = conn.cursor()
        
        # 查询最后一条记录
        query = "SELECT * FROM customer_inquiries ORDER BY created DESC LIMIT 1"
        cursor.execute(query)
        result = cursor.fetchone()
        
        cursor.close()
        conn.close()
        
        return result
    except Exception as e:
        print(f"数据库查询失败: {str(e)}")
        return None



last_record = get_last_record()
print(last_record)

if last_record:
    # 格式化记录为字符串
    record_str = "\n".join([f"{col}: {val}" for col, val in zip(cursor.column_names, last_record)])
    comb_text = f"""输入：{input_msg}
    
数据库最后一条记录：
{record_str}"""
else:
    # 如果没有记录，使用默认文本
    formatted_text = """0️⃣1️⃣ -0️⃣1⃣-300.00-1: 新到收
农行300w   24-25   万1"""
    comb_text = f"""输入：{input_msg}
    
{formatted_text}"""

# wx = WeChat()
# wx.SendMsg(comb_text, who="wx接受群")
